package com.media.selector.media.filter

import android.content.Context
import com.media.selector.media.model.IncapableCause
import com.media.selector.media.model.entity.MimeType
import com.media.selector.media.model.entity.MediaEntity

/**
 * date        ：2020/5/11
 * author      ：蒙景博
 * description ：
 */
abstract class Filter {

    /**
     * Against what mime types this filter applies.
     */
    protected abstract fun constraintTypes(): Set<MimeType>

    /**
     * Invoked for filtering each item.
     *
     * @return null if selectable, [IncapableCause] if not selectable.
     */
    abstract fun filter(context: Context?, item: MediaEntity?): IncapableCause?

    /**
     * Whether an [MediaEntity] need filtering.
     */
    protected fun needFiltering(context: Context, item: MediaEntity): Boolean {
        for (type in constraintTypes()) {
            if (type.checkType(context.contentResolver, item.contentUri)) {
                return true
            }
        }
        return false
    }
}